package com.zhongge.operations;

import com.zhongge.book.Book;
import com.zhongge.book.BookList;

import java.util.Scanner;

@SuppressWarnings("all")
/**
 * @ClassName ReturnBook
 * @Description TODO 归还图书
 * @Author zhongge
 * @Date 2025/7/14 19:34
 * @Version 1.0
 */
public class ReturnBook implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        System.out.println("请输入要归还的图书名字：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if (name.equals(book.getName()) && book.isBorrow() == true) {
                System.out.println("归还成功");
                book.setBorrow(false);
                return;
            } else {
                System.out.println("归还失败，此书不存在");
                return;
            }
        }
    }
}
